// pages/toBeSent/toBeSent.js
import api from '../../api/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
		active: 'waiting',
    listItems: [],
    id:'',
    companyid:'',
		page: 1,
		row: 10,
    total: 0,
    searchCondition: "",
    companylist:[],
  },
  onChange(e) {
		let that = this
		that.setData({
			active: e.detail.name,
			page: 1,
			// listItems: []
		})
   that.getCompanyOrder()
	},
	
	// async getList() {
	// 	try {
	// 		let that = this
	// 		let params = {
	// 			status: that.data.active,
	// 			page: that.data.page,
	// 			row: that.data.row
	// 		}
	// 		console.log('请求参数', params)
	// 		// 请求接口
	// 		// const data = await xxxxx(params)
	// 		that.setData({
	// 			listItems: that.data.listItems.concat(data.list),
	// 			total: data.total
	// 		})
	// 	} catch (error) {
	// 		console.log(error)
	// 	}
	// },
	
  goToMyBack(){
    wx.navigateBack()
  },
  goToUpdataLogistics(data){
    let shippingOrderNumber = data.currentTarget.dataset.index
    wx.navigateTo({
      url:'/pages/updateLogistics/updateLogistics?shippingOrderNumber='+shippingOrderNumber
    })
  },
  goToReceipt(data){
    let shippingOrderNumber = data.currentTarget.dataset.index
    wx.navigateTo({
      url:'/pages/receipt/receipt?shippingOrderNumber='+shippingOrderNumber
    })
  },
  arrivalNotice(data){
    let that =this
    let shippingOrderNumber = data.currentTarget.dataset.index
    var id = wx.getStorageSync('id')
    var companyid = wx.getStorageSync('companyid')
    let params={
     id:id,
     companyId:companyid,
     shippingOrderNumber:shippingOrderNumber
    }
    api.post('/app/logistics/arrivalNotice',params).then(res => {
      that.getCompanyOrder()
})
  },
 goToOrderDetail(data){
  let shippingOrderNumber = data.currentTarget.dataset.index
    wx.navigateTo({
      url:'/pages/orderDetail/orderDetail?shippingOrderNumber='+shippingOrderNumber
    })
  },
  immediateDelivery(data){
    let that =this 
   let shippingOrderNumber = data.currentTarget.dataset.index
   var id = wx.getStorageSync('id')
   var companyid = wx.getStorageSync('companyid')
   let params={
    userId:id,
    companyId:companyid,
    shippingOrderNumber:shippingOrderNumber
   }
    api.post('/companyInfoApp/updateStatus',params).then(res => {
        that.getCompanyOrder()
  })
  },
  clearSearch(){
    let that = this;
    that.getCompanyOrder()
  },
  onSearch(e){
    let that = this
    that.setData({
      searchCondition:e.detail
    })
    },
    onClick(){
      let that = this;
      that.getCompanyOrder()
    },
  getCompanyOrder(){
    let that = this;
    let companyid = wx.getStorageSync('companyid')
    that.setData({
      companyid:companyid,
    })
    let companyInfoReq = {
      shippingStatus: that.data.active,
      page: that.data.page,
      row: that.data.row,
      searchCondition:that.data.searchCondition,
      companyId:that.data.companyid
    }
    if(companyInfoReq.shippingStatus == 'all'){
      companyInfoReq.shippingStatus = ''
    }
    api.post('/companyInfoApp/findCompanyPage',companyInfoReq).then(res => {
        that.setData({
          companylist :res.data,
          total: res.data.total
        })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {//此处接收传递过来的参数wx.navigateTo跳转时传递的参数
		// console.log("页面传参",options.active);
		let that = this
    //如果要在页面中使用
    that.setData({
      active: options.active
    })
   that.getCompanyOrder()
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
		let that = this
    if (that.data.page * 10 < that.data.total) {
      that.setData({
        page: that.data.page += 1
      })
      // that.getList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})